// 引入SDK核心类
// var QQMapWX = require('../../utils/qqmap-wx-jssdk');
const lon = 116.479862
const lat = 39.945773
const tubiao = 'https://www.juquduo.com/static/resourse/dianwei/红标.png';
const gamebg = 'https://www.juquduo.com/static/resourse/yeshou/地图1.jpg'
var list = [] ;
// var mks=[];
var tempmks = [] ;
var num=0;
var obj = {"msg":list}
var all  = new Array();
var app = getApp()
var winnn = getApp().globalData.winwidth
var heigg = getApp().globalData.winheight

var mks = new Array()
//古水北镇的点
mks.push({id: 0,
      latitude: 40.647882,
      longitude: 117.271671,
      iconPath: tubiao,
      label:{
        content:'1',
      },
      width: 35,
      height: 40,},
      {id: 1,
      latitude: 40.647849,
      longitude: 117.271215,
      iconPath: tubiao,
      label:{
        content:'1-1',
      },
      width: 35,
      height: 40,},
      {id: 2,
      latitude: 40.648012,
      longitude: 117.271317,
      iconPath: tubiao,
      label:{content:'1-2',},
      width: 35,
      height: 40,},
      {id: 3,
      latitude: 40.647584,
      longitude: 117.271714,
      iconPath: tubiao,
      label:{content:'1-3',},
      width: 35,
      height: 40,},
      {id: 4,
      latitude: 40.648146,
      longitude: 117.272117,
      iconPath: tubiao,
      label:{content:'2',},
      width: 35,
      height: 40,},
      {id: 5,
      latitude: 40.648236,
      longitude: 117.271956,
      iconPath: tubiao,
      label:{content:'2-1',},
      width: 35,
      height: 40,},
      {
        id: 6,
        latitude: 40.648350,
        longitude: 117.271650,
        iconPath: tubiao,
        label:{content:'2-2',},
        width: 35,
        height: 40,
      },
      {
        id: 7,
        latitude: 40.647882,
        longitude: 117.272497,
        iconPath: tubiao,
        label:{content:'2-3',},
        width: 35,
        height: 40,
      },
      {
        id: 8,
        latitude: 40.648541,
        longitude: 117.272460,
        iconPath: tubiao,
       label:{ content:'3',  },
        width: 35,
        height: 40,
      },
      {
        id: 9,
        latitude: 40.648683,
        longitude: 117.272084,
        iconPath: tubiao,
        label:{content:'3-1',},
        width: 35,
        height: 40,
      },
      {
        id: 10,
        latitude: 40.648427,
        longitude: 117.273023,
        iconPath: tubiao,
        label:{content:'3-2',},
        width: 35,
        height: 40,
      },
      {
        id: 11,
        latitude: 40.648219,
        longitude: 117.273640,
        iconPath: tubiao,
        label:{content:'3-3',},
        width: 35,
        height: 40,
      },
      {
        id: 12,
        latitude: 40.649261,
        longitude: 117.273216,
        iconPath: tubiao,
       label:{ content:'4',  },

        width: 35,
        height: 40,
      },
      {
        id: 13,
        latitude: 40.648871,
        longitude: 117.273366,
        iconPath: tubiao,
        label:{content:'4-1',},
        width: 35,
        height: 40,
      },
      {
        id: 14,
        latitude: 40.649298,
        longitude: 117.273592,
        iconPath: tubiao,
        label:{content:'4-2',},
        width: 35,
        height: 40,
      },
      {
        id: 15,
        latitude: 40.649098,
        longitude: 117.274069,
        iconPath: tubiao,
        label:{content:'4-3',},
        width: 35,
        height: 40,
      },
      {
        id: 16,
        latitude: 40.649868,
        longitude: 117.274230,
        iconPath: tubiao,
        label:{ content:'5',  },

        width: 35,
        height: 40,
      },
      {
        id: 17,
        latitude: 40.650653,
        longitude: 117.273608,
        iconPath: tubiao,
        label:{content:'5-1',},
        width: 35,
        height: 40,
      },
      {
        id: 18,
        latitude: 40.650779,
        longitude: 117.272390,
        iconPath: tubiao,
        label:{content:'5-2',},
        width: 35,
        height: 40,
      },
      {
        id: 19,
        latitude: 40.650490,
        longitude: 117.275276,
        iconPath: tubiao,
        label:{content:'5-3',},
        width: 35,
        height: 40,
      },
      {
        id: 20,
        latitude: 40.651736,
        longitude: 117.273474,
        iconPath: tubiao,
        label:{ content:'6',  },
        width: 35,
        height: 40,
      },
      {
        id: 21,
        latitude: 40.651984,
        longitude: 117.274472,
        iconPath: tubiao,
        label:{content:'6-1',},
        width: 35,
        height: 40,
      },
      {
        id: 22,
        latitude: 40.651939,
        longitude: 117.272830,
        iconPath: tubiao,
        label:{content:'6-2',},
        width: 35,
        height: 40,
      },
      {
        id: 23,
        latitude: 40.651992,
        longitude: 117.276140,
        iconPath: tubiao,
        label:{content:'6-3',},
        width: 35,
        height: 40,
      },
      {
        id: 24,
        latitude: 40.652757,
        longitude: 117.276886,
        iconPath: tubiao,
        label:{ content:'7',  },
        width: 35,
        height: 40,
      },
      )
// 实例化API核心类
// var qqmapsdk = new QQMapWX({
//     key: app.globalData.key // 必填
// });  
 
//在Page({})中使用下列代码
Page({
  data:{
    mks:mks,
    jindutiao:'https://www.juquduo.com/static/resourse/dianwei/进度条1.png',
    dyxinxi:[],
    liebiao:[{activityType: "2",pointId: "4",pointName: "qqq"}],
    kedian:true,
    list:list,
    winheight:app.globalData.winheight,
    winwidth:app.globalData.winwidth,
    acid:'',
    num1:'0',
    usertype:'',
    // poi: {
    //   latitude: lat,
    //   longitude: lon,
    // }
    poi: {
      // 40.651297,117.273141
      latitude: 40.651297,
      longitude: 117.273141,
    }
  },
  onLoad:function(options){
    console.log('加载时，mks：')
    console.log(mks)
    var sdsdid = options.id
    var sdsdty = options.type
    if(sdsdid==''||sdsdid==undefined){
      console.log('没有活动id')
      this.setData({acid:166,usertype:1})}
      else{
        this.setData({acid:options.id,usertype:options.type})
      }
    try {
      wx.removeStorageSync('pointcont')
    } catch (e) {
      console.log('本地存储没有清除')
    }
  },
  onReady(){
    all.pop()
  },
  zhuye(){
    wx.redirectTo({
      url: '../ayeshou/yeshou',
    })
  },
  onShow(){
    var liebiao = wx.getStorageSync('pointcont') //取出内容之后删掉存储
    try {
      wx.removeStorageSync('pointcont')
    } catch (e) {
      // Do something when catch error
      console.log('本地存储没有清除')
    }
    
    // JSON.parse(liebiao)
    console.log('liebiao',liebiao)
    if(liebiao!=''){
      all.push(liebiao)//给下方列表添加一项
    }
    var _this = this;
    _this.setData({markers:mks,botthei:100+40*all.length})

    if(all.length>4){
      _this.setData({kedian:false,jindutiao:'https://www.juquduo.com/static/resourse/dianwei/进度条2.png'})
    }else{
      _this.setData({kedian:true,jindutiao:'https://www.juquduo.com/static/resourse/dianwei/进度条1.png'})
    }
    console.log('现在显示的列表:',all)
    console.log('现在显示的列表的长度:',all.length)
    _this.setData({liebiao:all})//显示下方的列表
    // _this.setData({markers:mks})
  },
  clickmap(e){
    var that = this
    var pid = e.detail.markerId
    // console.log(mks[pid])
    // mks = e.currentTarget.dataset.markers
    // 跳转参数
    var detail = mks[pid]
    console.log('被选中点的信息：')
    console.log(detail)
    console.log(detail.content)
    //修改覆盖物的文字
      var label = new Array
      num++
      var content='0'+num
      // var content=detail.content
      label.push({'content':content,'color':'#ffffff','anchorX':'-7','anchorY':'-32'})
      mks[pid].label={'content':content,'color':'#ffffff','anchorX':'-7','anchorY':'-32'}
      that.setData({
        num1:detail.content
      })
    wx.navigateTo({
      url: './dianweidetail?id='+pid+'&acid='+that.data.acid+'&lat='+detail.latitude+'&long='+detail.longitude+'&type='+that.data.usertype,
    })
    // 修改覆盖物的图片，重新加载覆盖物
    mks[pid].iconPath = 'https://www.juquduo.com/static/resourse/dianwei/顺序框1.png'
    console.log('点图标后，mks：')
    // console.log(mks)
    that.setData({markers:mks,botthei:100+40*list.length})

    // list用来调整页面参数，修改底部框的大小，显示按钮
    list.push(detail)

    that.setData({list:list})
  },
  tijiao(){
    // 跳转到分享页面，site为2，是楼下
    wx.navigateTo({
      url: '../cshare/share?acid='+this.data.acid+'&site='+2,
    })
  },
  deletpoint(e){
    console.log('点击删除')
    console.log(e)
    // 获取序号，用来删除，然后加载页面，修改底部框的大小
    var xuhao = e.currentTarget.dataset.id
    // all.remove(xuhao)
    all.splice(xuhao , 1)
    this.setData({liebiao:all,botthei:100+40*list.length})
    //参数传到服务器，删除数据
    var actype = e.currentTarget.dataset.key.activityType
    var poid = e.currentTarget.dataset.key.pointId
    var actid = this.data.acid
    wx.request({
      url: 'https://www.juquduo.com/juquduo/event/show?activityId=264&isRelease=1',
      data:{
        activityId:actid,
        activityType:actype,
        pointId:poid
      },
      success:function(res){
        console.log('删除成功')
        console.log(res)
      },
      fail(res){
        console.log(res)
      }
    })
  }
})